#coding=utf-8
#此脚本全部为函数，方便直接调用进行自动化测试
from selenium import webdriver
import time, datetime
import os
import sys
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.keys import Keys

#发车易贷
def op_che(adminname, password, borrowtitle, money, huankuanfangshi, rate, username_type, borrowname, month, cashgroup, agentname, rewardstate, rewardmode, reward):
    # 定义浏览器及地址
    reload(sys)
    sys.setdefaultencoding('utf-8')
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.implicitly_wait(8)
    driver.get("http://op.yidai.co/")
    #进行登录co环境的运营平台
    driver.find_element_by_id("adminname").send_keys(adminname)
    driver.find_element_by_id("password").send_keys(password)
    driver.find_element_by_id("authCode").send_keys(u"123456")
    driver.find_element_by_xpath(".//*[@id='submitFrom']/ul/li[4]/input").click()
    #判断是否登录成功，并输出至日志登录账号名称
    try:
        driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em")
        a = True
    except:
        a = False
    if a == True:
        username = driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em").text
        #进入发标页面
        driver.find_element_by_xpath(".//*[@id='header']/section[2]/nav/ul/li[8]/a").click()
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[2]/a").click()
        #发标页面第一页
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[1]/aside/label[1]/input").click()
        now = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))  # 标的编号命名格式
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[2]/aside/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[3]/aside/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[4]/aside/input").send_keys(borrowtitle+ now)
        Select(driver.find_element_by_id("username_type")).select_by_visible_text(username_type)
        driver.find_element_by_id("username").send_keys(borrowname)
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[5]/h6").click()
        if username_type == u"机构":
            driver.find_element_by_id("weituo_ren").send_keys(u"陈强270496")
            driver.find_element_by_id("wtUpload").send_keys("D:\\photo\\1.jpg")
            Select(driver.find_element_by_id("borrow_use")).select_by_visible_text(u"临时周转")
            driver.find_element_by_id("account").send_keys(money)
            driver.find_element_by_xpath(".//*[@id='borrow_style_box']/label[" + huankuanfangshi + "]/input").click()
            Select(driver.find_element_by_id("borrow_period")).select_by_visible_text(month)
            time.sleep(2)
            driver.find_element_by_id("borrow_apr").clear()
            driver.find_element_by_id("borrow_apr").send_keys(rate)
            Select(driver.find_element_by_xpath(".//*[@id='cashgroup']")).select_by_visible_text(cashgroup)
            driver.find_element_by_id("agent_username").send_keys(agentname)
            driver.find_element_by_link_text(u"下一步").click()
            #driver.find_element_by_xpath(".//*[@id='form1']/ul/li[6]/aside/input").send_keys(u"陈强")
            Select(driver.find_element_by_id("category")).select_by_visible_text(u"其他")
            driver.find_element_by_id("account_use").send_keys(u"借钱来耍耍")
            driver.find_element_by_link_text(u"下一步").click()
        if username_type == u"个人":
            Select(driver.find_element_by_id("borrow_use")).select_by_visible_text(u"临时周转")
            driver.find_element_by_id("account").send_keys(money)
            driver.find_element_by_xpath(".//*[@id='borrow_style_box']/label[" + huankuanfangshi + "]/input").click()
            Select(driver.find_element_by_id("borrow_period")).select_by_visible_text(month)
            time.sleep(2)
            driver.find_element_by_id("borrow_apr").clear()
            driver.find_element_by_id("borrow_apr").send_keys(rate)
            Select(driver.find_element_by_xpath(".//*[@id='cashgroup']")).select_by_visible_text(cashgroup)
            driver.find_element_by_id("agent_username").send_keys(agentname)
            driver.find_element_by_link_text(u"下一步").click()
            # 第二个页面
            Select(driver.find_element_by_id("edu")).select_by_visible_text(u"本科")
            driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[6]/aside/label[1]/input").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[7]/aside/input").send_keys(u"四川省南充市")
            driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[8]/aside/input").send_keys(u"四川省成都市青羊区")
            Select(driver.find_element_by_id("category")).select_by_visible_text(u"其他")
            driver.find_element_by_id("account_use").send_keys(u"借钱来耍耍")
            Select(driver.find_element_by_id("province")).select_by_visible_text(u"四川省")
            Select(driver.find_element_by_id("city")).select_by_visible_text(u"成都")
            driver.find_element_by_id("work_info").send_keys(u"工作很好，工资很高")
            driver.find_element_by_xpath(".//*[@id='form1']/ul[3]/li[7]/aside/span[1]/a").click()
        # 编辑发标的第三个页面
        driver.find_element_by_xpath(".//*[@id='car']/li[2]/aside/label[1]/input").click()
        driver.find_element_by_xpath(".//*[@id='car']/li[3]/aside/label[1]/input").click()
        driver.find_element_by_xpath(".//*[@id='car']/li[7]/aside/input").send_keys(u"100")
        driver.find_element_by_xpath(".//*[@id='car']/li[12]/aside/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul[6]/li/aside/input[3]").click()
        # 进入发标第四个页面,并判断是否有奖励标
        driver.find_element_by_xpath(".//*[@id='house']/li[2]/aside/label[" + rewardstate + "]/input").click()
        # rewardstate为1时为无奖励
        if rewardstate == "1":
            driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").click()
            # 切换iframe
            WebElementframe = driver.find_element_by_xpath("html/body/div/iframe")
            driver.switch_to.frame(WebElementframe)
            driver.find_element_by_id("dpTodayInput").click()
            driver.switch_to.default_content()
        # rewardstate为2时为有奖励
        if rewardstate == "2":
            driver.find_element_by_xpath(".//*[@id='status_type']/aside/label[" + rewardmode + "]/input").click()
            # rewardmode为1时为现金奖励
            if rewardmode == "1":
                driver.find_element_by_xpath(".//*[@id='status_1']/aside/input").send_keys(reward)
                driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").click()
                # 切换iframe
                WebElementframe = driver.find_element_by_xpath("html/body/div/iframe")
                driver.switch_to.frame(WebElementframe)
                driver.find_element_by_id("dpTodayInput").click()
                driver.switch_to.default_content()
            # rewardmode为2时为按投资金额比例奖励
            if rewardmode == "2":
                driver.find_element_by_xpath(".//*[@id='status_2']/aside/input").send_keys(reward)
                driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").click()
                # 切换iframe
                WebElementframe = driver.find_element_by_xpath("html/body/div/iframe")
                driver.switch_to.frame(WebElementframe)
                driver.find_element_by_id("dpTodayInput").click()
                driver.switch_to.default_content()
        driver.find_element_by_xpath(".//*[@id='house']/li[12]/aside/span[1]/a").click()
        #判断是否发布标的成功
        #进入标的批次号管理页面查看是否发布成功
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[11]/a").click()
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/a").click()
        try:
            driver.find_element_by_xpath(".//*[@id='yfm']")
            b = True
        except:
            b = False
        if b == True:
            text = driver.find_element_by_xpath(".//*[@id='yfm']").text
            borrowid = driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr/td[2]").text
            driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr[1]/td[1]/input").click()  # 勾选第一个标的进行生成批次号
            driver.find_element_by_xpath("html/body/main/section/div[2]/a").click()
            time.sleep(2)
            driver.find_element_by_xpath(".//*[@id='form_yhk']/ul/li[4]/input[1]").click()
            time.sleep(2)
            driver.find_element_by_xpath(".//*[@id='form_yhk']/ul/li[3]/input[2]").click()
            # 再次搜索对应用户名的标
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/a").click()
            driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr/td[1]/input").click()
            driver.find_element_by_xpath("html/body/main/section/div[2]/a[2]").click()
            time.sleep(2)
            driver.find_element_by_xpath(u"(//input[@value='确定'])[2]").click()
            time.sleep(2)
            driver.find_element_by_xpath(u"//input[@value='进入标的初审']").click()
            # 进入标的初审页面,并按照借款编号进行搜索标的
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"借款编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(borrowid)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
            # 进入初审页面
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/aside/label[1]/input").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/aside/textarea").send_keys(u"审核审核")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/aside/span[1]/a").click()
            time.sleep(3)
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"借款编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(borrowid)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
            # 提交二审
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr[1]/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='house']/li[12]/aside/span[1]/a").click()
            time.sleep(3)
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"借款编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(borrowid)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/aside/label[1]/input").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/aside/textarea").send_keys(u"审核审核")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/aside/span[1]/a").click()
            # 执行发标连接，进入投资中的借款
            driver.get("http://task.yidai.co/worthautoissue.task.php")
            time.sleep(2)
            driver.refresh()
            driver.quit()
            return u"借款标题是：" + borrowtitle + now + u",借款人是：" + borrowname  + u"，借款编号是：" + borrowid
        if b == False:
            driver.quit()
            return u"发标失败"
    if a == False:
        driver.quit()
        return u"登录失败"


#发房易贷
def op_fang(adminname, password, borrowtitle, money, huankuanfangshi, rate, username_type, borrowname, month, cashgroup, agentname, rewardstate, rewardmode, reward):
    # 定义浏览器及地址
    reload(sys)
    sys.setdefaultencoding('utf-8')
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.implicitly_wait(8)
    driver.get("http://op.yidai.co/")
    # 进行登录co环境的运营平台
    driver.find_element_by_id("adminname").send_keys(adminname)
    driver.find_element_by_id("password").send_keys(password)
    driver.find_element_by_id("authCode").send_keys(u"123456")
    driver.find_element_by_xpath(".//*[@id='submitFrom']/ul/li[4]/input").click()
    # 判断是否登录成功，并输出至日志登录账号名称
    try:
        driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em")
        a = True
    except:
        a = False
    if a == True:
        username = driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em").text
        driver.find_element_by_xpath(".//*[@id='header']/section[2]/nav/ul/li[8]/a").click()
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[2]/a").click()
        #进入发标的第一个页面
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[1]/aside/label[2]/input").click()
        now = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))  # 标的编号命名格式
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[2]/aside/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[3]/aside/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[4]/aside/input").send_keys(borrowtitle + now)
        Select(driver.find_element_by_id("username_type")).select_by_visible_text(username_type)
        driver.find_element_by_id("username").send_keys(borrowname)
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[5]/h6").click()
        if username_type == u"机构":
            driver.find_element_by_id("weituo_ren").send_keys(u"陈强270496")
            driver.find_element_by_id("wtUpload").send_keys("D:\\photo\\1.jpg")
            Select(driver.find_element_by_id("borrow_use")).select_by_visible_text(u"临时周转")
            driver.find_element_by_id("account").send_keys(money)
            driver.find_element_by_xpath(".//*[@id='borrow_style_box']/label[" + huankuanfangshi + "]/input").click()
            Select(driver.find_element_by_id("borrow_period")).select_by_visible_text(month)
            time.sleep(2)
            driver.find_element_by_id("borrow_apr").clear()
            driver.find_element_by_id("borrow_apr").send_keys(rate)
            Select(driver.find_element_by_xpath(".//*[@id='cashgroup']")).select_by_visible_text(cashgroup)
            driver.find_element_by_id("agent_username").send_keys(agentname)
            driver.find_element_by_link_text(u"下一步").click()
            #driver.find_element_by_xpath(".//*[@id='form1']/ul/li[6]/aside/input").send_keys(u"陈强")
            Select(driver.find_element_by_id("category")).select_by_visible_text(u"其他")
            driver.find_element_by_id("account_use").send_keys(u"借钱来耍耍")
            driver.find_element_by_link_text(u"下一步").click()
        if username_type == u"个人":
            Select(driver.find_element_by_id("borrow_use")).select_by_visible_text(u"临时周转")
            driver.find_element_by_id("account").send_keys(money)
            driver.find_element_by_xpath(".//*[@id='borrow_style_box']/label[" + huankuanfangshi + "]/input").click()
            Select(driver.find_element_by_id("borrow_period")).select_by_visible_text(month)
            time.sleep(2)
            driver.find_element_by_id("borrow_apr").clear()
            driver.find_element_by_id("borrow_apr").send_keys(rate)
            Select(driver.find_element_by_xpath(".//*[@id='cashgroup']")).select_by_visible_text(cashgroup)
            driver.find_element_by_id("agent_username").send_keys(agentname)
            driver.find_element_by_link_text(u"下一步").click()
            # 第二个页面
            driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[3]/aside/input").send_keys(u"17700010001")
            Select(driver.find_element_by_id("edu")).select_by_visible_text(u"本科")
            driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[6]/aside/label[1]/input").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[7]/aside/input").send_keys(u"四川省南充市")
            driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[8]/aside/input").send_keys(u"四川省成都市青羊区")
            Select(driver.find_element_by_id("category")).select_by_visible_text(u"其他")
            driver.find_element_by_id("account_use").send_keys(u"借钱来耍耍")
            Select(driver.find_element_by_id("province")).select_by_visible_text(u"四川省")
            Select(driver.find_element_by_id("city")).select_by_visible_text(u"成都")
            driver.find_element_by_id("work_info").send_keys(u"工作很好，工资很高")
            driver.find_element_by_xpath(".//*[@id='form1']/ul[3]/li[7]/aside/span[1]/a").click()
        #进入发标第三个页面
        # 切换iframe
        driver.switch_to.frame("iframebox1")
        Select(driver.find_element_by_xpath(".//*[@id='house_type']")).select_by_visible_text(u"商品房")
        driver.find_element_by_xpath(".//*[@id='house']/li[3]/aside/label[1]/input").click()
        driver.find_element_by_xpath(".//*[@id='house']/li[5]/aside/input").send_keys(u"2015-07-25")
        driver.find_element_by_xpath(".//*[@id='house']/li[6]/aside/input").send_keys(u"100")
        driver.find_element_by_xpath(".//*[@id='house']/li[8]/aside/input").send_keys(u"成都市公证处")
        driver.find_element_by_id("house_money").send_keys(u"100")
        driver.find_element_by_id("house_area").send_keys(u"100")
        driver.find_element_by_id("house_address").send_keys(u"成都市天府广场")
        driver.find_element_by_id("house_byuser").send_keys(u"陈强")
        Select(driver.find_element_by_id("house_byuser_type")).select_by_visible_text(u"单独所有")
        driver.find_element_by_xpath(".//*[@id='house']/li[14]/aside/input").send_keys(now)
        driver.switch_to.default_content()
        driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li/aside/input[4]").click()
        # 进入发标第四个页面,并判断是否有奖励标
        driver.find_element_by_xpath(".//*[@id='house']/li[2]/aside/label[" + rewardstate + "]/input").click()
        # rewardstate为1时为无奖励
        if rewardstate == "1":
            driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").click()
            # 切换iframe
            WebElementframe = driver.find_element_by_xpath("html/body/div/iframe")
            driver.switch_to.frame(WebElementframe)
            driver.find_element_by_id("dpTodayInput").click()
            driver.switch_to.default_content()
        # rewardstate为2时为有奖励
        if rewardstate == "2":
            driver.find_element_by_xpath(".//*[@id='status_type']/aside/label[" + rewardmode + "]/input").click()
            # rewardmode为1时为现金奖励
            if rewardmode == "1":
                driver.find_element_by_xpath(".//*[@id='status_1']/aside/input").send_keys(reward)
                driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").click()
                # 切换iframe
                WebElementframe = driver.find_element_by_xpath("html/body/div/iframe")
                driver.switch_to.frame(WebElementframe)
                driver.find_element_by_id("dpTodayInput").click()
                driver.switch_to.default_content()
            # rewardmode为2时为按投资金额比例奖励
            if rewardmode == "2":
                driver.find_element_by_xpath(".//*[@id='status_2']/aside/input").send_keys(reward)
                driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").click()
                # 切换iframe
                WebElementframe = driver.find_element_by_xpath("html/body/div/iframe")
                driver.switch_to.frame(WebElementframe)
                driver.find_element_by_id("dpTodayInput").click()
                driver.switch_to.default_content()
        driver.find_element_by_xpath(".//*[@id='house']/li[12]/aside/span[1]/a").click()
        # 判断是否发布标的成功
        # 进入标的批次号管理页面查看是否发布成功
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[11]/a").click()
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/a").click()
        try:
            driver.find_element_by_xpath(".//*[@id='yfm']")
            b = True
        except:
            b = False
        if b == True:
            text = driver.find_element_by_xpath(".//*[@id='yfm']").text
            borrowid = driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr/td[2]").text
            driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr[1]/td[1]/input").click()  # 勾选第一个标的进行生成批次号
            driver.find_element_by_xpath("html/body/main/section/div[2]/a").click()
            time.sleep(2)
            driver.find_element_by_xpath(".//*[@id='form_yhk']/ul/li[4]/input[1]").click()
            time.sleep(2)
            driver.find_element_by_xpath(".//*[@id='form_yhk']/ul/li[3]/input[2]").click()
            # 再次搜索对应用户名的标
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/a").click()
            driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr/td[1]/input").click()
            driver.find_element_by_xpath("html/body/main/section/div[2]/a[2]").click()
            time.sleep(2)
            driver.find_element_by_xpath(u"(//input[@value='确定'])[2]").click()
            time.sleep(2)
            driver.find_element_by_xpath(u"//input[@value='进入标的初审']").click()
            # 进入标的初审页面,并按照借款编号进行搜索标的
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"借款编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(borrowid)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
            # 进入初审页面
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/aside/label[1]/input").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/aside/textarea").send_keys(u"审核审核")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/aside/span[1]/a").click()
            time.sleep(3)
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"借款编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(borrowid)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
            # 提交二审
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr[1]/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='house']/li[12]/aside/span[1]/a").click()
            time.sleep(3)
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"借款编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(borrowid)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/aside/label[1]/input").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/aside/textarea").send_keys(u"审核审核")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/aside/span[1]/a").click()
            # 执行发标连接，进入投资中的借款
            driver.get("http://task.yidai.co/worthautoissue.task.php")
            time.sleep(2)
            driver.refresh()
            driver.quit()
            return u"借款标题是：" + borrowtitle + now + u",借款人是：" + borrowname  + u"，借款编号是：" + borrowid
        if b == False:
            driver.quit()
            return u"发标失败"
    if a == False:
        driver.quit()
        return u"登录失败"

def op_Fdl(adminname, password, borrowtitle, money, rate, borrowname, month, agentname, rewardstate, rewardmode, reward, P2P_username, P2P_password, paypassword, date):
    #op_Fdl(运营平台账号, 运营平台密码, 借款金额, 借款年利率, 借款人, P2P登录账号, P2P登录密码, P2P交易密码, 满标复审日期)
    # 定义浏览器及地址
    reload(sys)
    sys.setdefaultencoding('utf-8')
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.implicitly_wait(8)
    driver.get("http://op.yidai.co/")
    # 进行登录co环境的运营平台
    driver.find_element_by_id("adminname").send_keys(adminname)
    driver.find_element_by_id("password").send_keys(password)
    driver.find_element_by_id("authCode").send_keys(u"123456")
    driver.find_element_by_xpath(".//*[@id='submitFrom']/ul/li[4]/input").click()
    # 判断是否登录成功，并输出至日志登录账号名称
    try:
        driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em")
        a = True
    except:
        a = False
    if a == True:
        username = driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em").text
        os.chdir('D:\python-photo\log')  # 切换到当前目录
        report = open("OP-login.doc", "a")  # 打开报告
        current_time = datetime.datetime.now()
        report.write("\n%s:" % current_time)
        report.write("开始发标，登录成功,账号昵称是：" + username + "\n")
        driver.find_element_by_xpath(".//*[@id='header']/section[2]/nav/ul/li[8]/a").click()
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[2]/a").click()
        #第一个页面
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[1]/aside/label[3]/input").click()
        now = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))  # 标的编号命名格式,也为业务编号
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[2]/aside/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[3]/aside/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[4]/aside/input").send_keys(borrowtitle + now)
        driver.find_element_by_id("username").send_keys(borrowname)
        Select(driver.find_element_by_id("borrow_use")).select_by_visible_text(u"临时周转")
        driver.find_element_by_id("account").send_keys(money)
        driver.find_element_by_xpath(".//*[@id='borrow_style_box']/label[1]/input").click()
        Select(driver.find_element_by_id("borrow_period")).select_by_visible_text(month)
        time.sleep(2)
        driver.find_element_by_id("borrow_apr").clear()
        driver.find_element_by_id("borrow_apr").send_keys(rate)
        Select(driver.find_element_by_id("cashgroup")).select_by_visible_text(u"提现到债权管理人")
        driver.find_element_by_id("agent_username").send_keys(agentname)
        driver.find_element_by_link_text(u"下一步").click()
        #第二个页面
        Select(driver.find_element_by_id("edu")).select_by_visible_text(u"本科")
        driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[6]/aside/label[1]/input").click()
        driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[7]/aside/input").send_keys(u"四川省南充市")
        driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[8]/aside/input").send_keys(u"四川省成都市青羊区")
        driver.find_element_by_id("account_use").send_keys(u"借钱来耍耍")
        Select(driver.find_element_by_id("province")).select_by_visible_text(u"四川省")
        Select(driver.find_element_by_id("city")).select_by_visible_text(u"成都")
        driver.find_element_by_id("work_info").send_keys(u"工作很好，工资很高")
        driver.find_element_by_xpath(".//*[@id='form1']/ul[3]/li[7]/aside/span[1]/a").click()
        # 进入发标第三个页面
        # 切换iframe
        driver.switch_to.frame("iframebox1")
        Select(driver.find_element_by_xpath(".//*[@id='house_type']")).select_by_visible_text(u"商品房")
        driver.find_element_by_xpath(".//*[@id='house']/li[3]/aside/label[1]/input").click()
        driver.find_element_by_xpath(".//*[@id='house']/li[5]/aside/input").send_keys(u"2015-07-25")
        Select(driver.find_element_by_id("house_live_type")).select_by_visible_text(u"套一")
        Select(driver.find_element_by_id("house_zxqk")).select_by_visible_text(u"精装")
        driver.find_element_by_xpath(".//*[@id='house']/li[8]/aside/input").send_keys(u"100")
        driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").send_keys(u"成都长富新城")
        driver.find_element_by_xpath(".//*[@id='house']/li[10]/aside/input").send_keys(u"房子不错")
        driver.find_element_by_id("house_money").send_keys(u"100")
        driver.find_element_by_id("house_area").send_keys(u"100")
        driver.find_element_by_id("house_address").send_keys(u"成都市天府广场" + now)
        driver.find_element_by_id("house_byuser").send_keys(u"陈强")
        Select(driver.find_element_by_id("house_byuser_type")).select_by_visible_text(u"单独所有")
        driver.find_element_by_xpath(".//*[@id='house']/li[16]/aside/input").send_keys(u"王爆炸")
        Select(driver.find_element_by_id("house_card_type")).select_by_visible_text(u"产权证")
        driver.find_element_by_xpath(".//*[@id='house']/li[18]/aside/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='house']/li[19]/aside/input").send_keys(u"1000")
        driver.find_element_by_xpath(".//*[@id='house']/li[20]/aside/input").send_keys(u"1200")
        driver.find_element_by_xpath(".//*[@id='house']/li[21]/aside/input").send_keys(u"陈强")
        driver.find_element_by_xpath(".//*[@id='house']/li[22]/aside/input").send_keys(u"20000")
        driver.find_element_by_xpath(".//*[@id='house']/li[23]/aside/input[1]").send_keys(u"2017-07-25")
        driver.find_element_by_xpath(".//*[@id='house']/li[23]/aside/input[2]").send_keys(u"2018-07-25")
        driver.find_element_by_xpath(".//*[@id='house']/li[24]/aside/input").send_keys(u"天宸汇力商业保理（深圳）有限公司")
        driver.find_element_by_xpath(".//*[@id='house']/li[25]/aside/input").send_keys(u"2015-09-04")
        driver.switch_to.default_content()
        driver.find_element_by_xpath("//*[@id='form1']/ul[2]/li[3]/aside/input[4]").click()
        # 进入发标第四个页面,并判断是否有奖励标
        driver.find_element_by_xpath(".//*[@id='house']/li[2]/aside/label[" + rewardstate + "]/input").click()
        # rewardstate为1时为无奖励
        if rewardstate == "1":
            driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").click()
            # 切换iframe
            WebElementframe = driver.find_element_by_xpath("html/body/div/iframe")
            driver.switch_to.frame(WebElementframe)
            driver.find_element_by_id("dpTodayInput").click()
            driver.switch_to.default_content()
        # rewardstate为2时为有奖励
        if rewardstate == "2":
            driver.find_element_by_xpath(".//*[@id='status_type']/aside/label[" + rewardmode + "]/input").click()
            # rewardmode为1时为现金奖励
            if rewardmode == "1":
                driver.find_element_by_xpath(".//*[@id='status_1']/aside/input").send_keys(reward)
                driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").click()
                # 切换iframe
                WebElementframe = driver.find_element_by_xpath("html/body/div/iframe")
                driver.switch_to.frame(WebElementframe)
                driver.find_element_by_id("dpTodayInput").click()
                driver.switch_to.default_content()
            # rewardmode为2时为按投资金额比例奖励
            if rewardmode == "2":
                driver.find_element_by_xpath(".//*[@id='status_2']/aside/input").send_keys(reward)
                driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").click()
                # 切换iframe
                WebElementframe = driver.find_element_by_xpath("html/body/div/iframe")
                driver.switch_to.frame(WebElementframe)
                driver.find_element_by_id("dpTodayInput").click()
                driver.switch_to.default_content()
        #截图并保存
        #pic_path = 'D:\\python-photo\\image\\' + now + 'FDL-biao' + '.png'  # 截图保存路径
        #print pic_path
        #driver.save_screenshot(pic_path)  # 截图
        driver.find_element_by_xpath(".//*[@id='house']/li[12]/aside/span[1]/a").click()
        # 判断是否发布标的成功
        #根据业务编号进行搜索标，并进行审核
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[4]/a").click()
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
        #判断是否发布成功
        try:
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]")
            b = True
        except:
            b = False
        if b == True:
            borrowid = driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr/td[1]").text
            print u"借款编号是：" + borrowid
            #进行第一次审核
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/aside/label[1]/input").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/aside/textarea").send_keys(u"审核成功")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/aside/span[1]/a").click()
            #按照业务编号进行搜索标
            driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[4]/a").click()
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
            #进行第二次审核
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='house']/li[12]/aside/span[1]/a").click()
            # 按照业务编号进行搜索标
            driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[4]/a").click()
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
            #进行第三次审核
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/aside/label[1]/input").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/aside/textarea").send_keys(u"审核成功")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/aside/span[1]/a").click()
            #初审完毕，执行发标计划任务，进入投资中的借款
            driver.get("http://task.yidai.co/worthautoissue.task.php")
            time.sleep(3)
            driver.refresh()
            #进入投资中的借款，搜索是否已经发布成功
            # 进行登录co环境的运营平台
            driver.get("http://op.yidai.co/")
            driver.find_element_by_id("adminname").send_keys(adminname)
            driver.find_element_by_id("password").send_keys(password)
            driver.find_element_by_id("authCode").send_keys(u"123456")
            driver.find_element_by_xpath(".//*[@id='submitFrom']/ul/li[4]/input").click()
            driver.find_element_by_xpath(".//*[@id='header']/section[2]/nav/ul/li[8]/a").click()
            driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[6]/a").click()
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"借款编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(borrowid)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
            try:
                driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[2]")
                c = True
            except:
                c = False
            if c == True:
                print u"发布房东贷标成功，状态为投资中"
                #进入P2P前台进行投资满标
                #进入投标页面
                driver.get("https://www.yidai.co/invest/a" + borrowid +".html")
                #登录P2P前台页面
                driver.find_element_by_xpath("html/body/div[1]/div[1]/div[2]/div/div/div[1]/div/a[1]").click()
                driver.find_element_by_id("keywords").send_keys(P2P_username)
                driver.find_element_by_id("password").send_keys(P2P_password)
                driver.find_element_by_id("login_button").click()
                driver.find_element_by_xpath(".//*[@id='investForm']/div[1]/input[2]").click()
                driver.find_element_by_id("paypassword").send_keys(paypassword)
                driver.find_element_by_id("valicode").send_keys(u"1704")
                driver.find_element_by_id("submit_button").click()
                #再次进入运营平台进行满标复审
                driver.get("http://op.yidai.co/")
                driver.find_element_by_id("adminname").send_keys(adminname)
                driver.find_element_by_id("password").send_keys(password)
                driver.find_element_by_id("authCode").send_keys(u"123456")
                driver.find_element_by_xpath(".//*[@id='submitFrom']/ul/li[4]/input").click()
                driver.find_element_by_xpath(".//*[@id='header']/section[2]/nav/ul/li[8]/a").click()
                driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[5]/a").click()
                Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"借款编号")
                driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input[2]").send_keys(borrowid)
                driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/a").click()
                driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr[1]/td/a[1]").click()
                #进入满标复审详情页面
                driver.find_element_by_xpath(".//*[@id='checkCDY']").click()
                driver.find_element_by_xpath(".//*[@id='remark']/aside/textarea").send_keys(u"审核成功")
                driver.find_element_by_xpath(".//*[@id='resub']/aside/span[1]/a").click()
                #执行满标复审的连接
                driver.get("http://api.yidai.co/apitest/test/?borrowId="+ borrowid +"&issueDay="+ date)
                message = driver.find_element_by_xpath("html/body").text
                print message
                driver.quit()
                return u"满标复审成功，借款标题是：" + borrowtitle + now + u",借款人是：" + borrowname  + u"，借款编号是：" + borrowid + '。' + message

            if c == False:
                print u"房东贷标未发布到投资中，再执行一次发标计划任务"
                #再次执行发标计划任务
                driver.get("http://task.yidai.co/worthautoissue.task.php")
                driver.refresh()
                # 进入P2P前台进行投资满标
                # 进入投标页面
                time.sleep(3)
                driver.get("https://www.yidai.co/invest/a" + borrowid + ".html")
                # 登录P2P前台页面
                driver.find_element_by_xpath("html/body/div[1]/div[1]/div[2]/div/div/div[1]/div/a[1]").click()
                driver.find_element_by_id("keywords").send_keys(P2P_username)
                driver.find_element_by_id("password").send_keys(P2P_password)
                driver.find_element_by_id("login_button").click()
                driver.find_element_by_xpath(".//*[@id='investForm']/div[1]/input[2]").click()
                driver.find_element_by_id("paypassword").send_keys(paypassword)
                driver.find_element_by_id("valicode").send_keys(u"1704")
                driver.find_element_by_id("submit_button").click()
                # 再次进入运营平台进行满标复审
                driver.get("http://op.yidai.co/")
                driver.find_element_by_id("adminname").send_keys(adminname)
                driver.find_element_by_id("password").send_keys(password)
                driver.find_element_by_id("authCode").send_keys(u"123456")
                driver.find_element_by_xpath(".//*[@id='submitFrom']/ul/li[4]/input").click()
                driver.find_element_by_xpath(".//*[@id='header']/section[2]/nav/ul/li[8]/a").click()
                driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[5]/a").click()
                Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"借款编号")
                driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input[2]").send_keys(borrowid)
                driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/a").click()
                driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr[1]/td/a[1]").click()
                # 进入满标复审详情页面
                driver.find_element_by_xpath(".//*[@id='checkCDY']").click()
                driver.find_element_by_xpath(".//*[@id='remark']/aside/textarea").send_keys(u"审核成功")
                driver.find_element_by_xpath(".//*[@id='resub']/aside/span[1]/a").click()
                # 执行满标复审的连接
                driver.get("http://api.yidai.co/apitest/test/?borrowId=" + borrowid + "&issueDay=" + date)
                message = driver.find_element_by_xpath("html/body").text
                print message
                driver.quit()
                return u"再次执行一次出标队列计划任务，满标复审成功，借款标题是：" + borrowtitle + now + u",借款人是：" + borrowname  + u"，借款编号是：" + borrowid + '。' + message

        if b == False:
            print u"发布标失败"
            driver.quit()
            return u"发标失败"

    if a == False:
        os.chdir('D:\python-photo\log')  # 切换到当前目录
        report = open("OP-login.doc", "a")  # 打开报告
        current_time = datetime.datetime.now()
        report.write("\n%s:" % current_time)
        report.write("登录失败\n")
        driver.quit()





#生成批次号和初审
def review(adminname, password, borrowname):
    reload(sys)
    sys.setdefaultencoding('utf-8')
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.implicitly_wait(8)
    driver.get("http://op.yidai.co/")
    # 进行登录co环境的运营平台
    driver.find_element_by_id("adminname").send_keys(adminname)
    driver.find_element_by_id("password").send_keys(password)
    driver.find_element_by_id("authCode").send_keys(u"123456")
    driver.find_element_by_xpath(".//*[@id='submitFrom']/ul/li[4]/input").click()
    # 判断是否登录成功，并输出至日志登录账号名称
    try:
        driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em")
        a = True
    except:
        a = False
    if a == True:
        username = driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em").text
        os.chdir('D:\python-photo\log')  # 切换到当前目录
        report = open("OP-login.doc", "a")  # 打开报告
        current_time = datetime.datetime.now()
        report.write("\n%s:" % current_time)
        report.write("开始审核标，登录成功,账号昵称是：" + username + "\n")
        driver.find_element_by_xpath(".//*[@id='header']/section[2]/nav/ul/li[8]/a").click()
        #进入标的批次号管理页面,并搜索对应用户名的标进行批次号管理
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[11]/a").click()
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"用户名")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(borrowname)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/a").click()
        borrowid = driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr[1]/td[2]").text  #获取借款编号
        print borrowid
        driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr[1]/td[1]/input").click()  #勾选第一个标的进行生成批次号
        driver.find_element_by_xpath("html/body/main/section/div[2]/a").click()
        time.sleep(2)
        driver.find_element_by_xpath(".//*[@id='form_yhk']/ul/li[4]/input[1]").click()
        time.sleep(2)
        driver.find_element_by_xpath(".//*[@id='form_yhk']/ul/li[3]/input[2]").click()
        #再次搜索对应用户名的标
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"用户名")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(borrowname)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/a").click()
        driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr/td[1]/input").click()
        driver.find_element_by_xpath("html/body/main/section/div[2]/a[2]").click()
        time.sleep(2)
        driver.find_element_by_xpath(u"(//input[@value='确定'])[2]").click()
        time.sleep(2)
        driver.find_element_by_xpath(u"//input[@value='进入标的初审']").click()
        #进入标的初审页面,并按照借款编号进行搜索标的
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"借款编号")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(borrowid)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
        #进入初审页面
        driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/aside/label[1]/input").click()
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/aside/textarea").send_keys(u"审核审核")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/aside/span[1]/a").click()
        time.sleep(3)
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"借款编号")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(borrowid)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
        #提交二审
        driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr[1]/td/a[1]").click()
        driver.find_element_by_xpath(".//*[@id='house']/li[12]/aside/span[1]/a").click()
        time.sleep(3)
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"借款编号")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(borrowid)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
        driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/aside/label[1]/input").click()
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/aside/textarea").send_keys(u"审核审核")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/aside/span[1]/a").click()
        #执行发标连接，进入投资中的借款
        driver.get("http://task.yidai.co/worthautoissue.task.php")
        time.sleep(2)
        driver.quit()
    if a == False:
        os.chdir('D:\python-photo\log')  # 切换到当前目录
        report = open("OP-login.doc", "a")  # 打开报告
        current_time = datetime.datetime.now()
        report.write("\n%s:" % current_time)
        report.write("开始审核表，登录失败\n")
        driver.quit()

#第一步流标处理
def op_liubiao_01(adminname, password, borrowname):
    reload(sys)
    sys.setdefaultencoding('utf-8')
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.implicitly_wait(8)
    driver.get("http://op.yidai.co/")
    # 进行登录co环境的运营平台
    driver.find_element_by_id("adminname").send_keys(adminname)
    driver.find_element_by_id("password").send_keys(password)
    driver.find_element_by_id("authCode").send_keys(u"123456")
    driver.find_element_by_xpath(".//*[@id='submitFrom']/ul/li[4]/input").click()
    # 判断是否登录成功，并输出至日志登录账号名称
    try:
        driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em")
        a = True
    except:
        a = False
    if a == True:
        username = driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em").text
        os.chdir('D:\python-photo\log')  # 切换到当前目录
        report = open("OP-login.doc", "a")  # 打开报告
        current_time = datetime.datetime.now()
        report.write("\n%s:" % current_time)
        report.write("开始审核标，登录成功,账号昵称是：" + username + "\n")
        driver.find_element_by_xpath(".//*[@id='header']/section[2]/nav/ul/li[8]/a").click()
        # 进入标的批次号管理页面,并搜索对应用户名的标进行批次号管理
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[11]/a").click()
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"用户名")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(borrowname)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/a").click()
        borrowid = driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr[1]/td[2]").text  # 获取借款编号
        driver.find_element_by_xpath(
            ".//*[@id='tabScroll']/div/table/tbody/tr[1]/td[1]/input").click()  # 勾选第一个标的进行生成批次号
        driver.find_element_by_xpath("html/body/main/section/div[2]/a").click()
        time.sleep(2)
        driver.find_element_by_xpath(".//*[@id='form_yhk']/ul/li[4]/input[1]").click()
        time.sleep(2)
        driver.find_element_by_xpath(".//*[@id='form_yhk']/ul/li[3]/input[2]").click()
        # 再次搜索对应用户名的标
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"用户名")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(borrowname)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/a").click()
        driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr/td[1]/input").click()
        driver.find_element_by_xpath("html/body/main/section/div[2]/a[2]").click()
        time.sleep(2)
        driver.find_element_by_xpath(u"(//input[@value='确定'])[2]").click()
        time.sleep(2)
        driver.find_element_by_xpath(u"//input[@value='进入标的初审']").click()
        # 进入标的初审页面,并按照借款编号进行搜索标的
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"借款编号")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(borrowid)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
        # 进入初审页面
        driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/aside/label[3]/input").click()
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/aside/textarea").send_keys(u"流标处理")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/aside/span[1]/a").click()
        #在标的列表中查看状态是否为已流标
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[1]/a").click()
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"借款编号")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/input").send_keys(borrowid)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/a").click()
        message = driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr/td[1]").text
        #判断当前状态是否为申请失败
        if message == "申请失败":
            os.chdir('D:\python-photo\log')  # 切换到当前目录
            report = open("OP-login.doc", "a")  # 打开报告
            current_time = datetime.datetime.now()
            report.write("%s:" % current_time)
            report.write("流标成功，当前状态为："+ message + "\n")
        else:
            os.chdir('D:\python-photo\log')  # 切换到当前目录
            report = open("OP-login.doc", "a")  # 打开报告
            current_time = datetime.datetime.now()
            report.write("%s:" % current_time)
            report.write("流标失败，当前状态为：" + message + "\n")
            driver.quit()
    if a == False:
        os.chdir('D:\python-photo\log')  # 切换到当前目录
        report = open("OP-login.doc", "a")  # 打开报告
        current_time = datetime.datetime.now()
        report.write("\n%s:" % current_time)
        report.write("开始审核表，登录失败\n")
        driver.quit()

def op_duilie(adminname, password, borrowtitle, money, rate, cashgroup,borrowname, month, agentname, rewardstate, rewardmode, reward):
    #op_Fdl(运营平台账号, 运营平台密码, 借款金额, 借款年利率, 借款人, P2P登录账号, P2P登录密码, P2P交易密码, 满标复审日期)
    # 定义浏览器及地址
    reload(sys)
    sys.setdefaultencoding('utf-8')
    #driverOptions = webdriver.ChromeOptions()
    #driverOptions.add_argument(r"user-data-dir=C:\Users\56443\AppData\Local\Google\Chrome\User Data\Default")
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.implicitly_wait(8)
    driver.get("http://op.yidai.co/")
    # 进行登录co环境的运营平台
    driver.find_element_by_id("adminname").send_keys(adminname)
    driver.find_element_by_id("password").send_keys(password)
    driver.find_element_by_id("authCode").send_keys(u"123456")
    driver.find_element_by_xpath(".//*[@id='submitFrom']/ul/li[4]/input").click()
    # 判断是否登录成功，并输出至日志登录账号名称
    try:
        driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em")
        a = True
    except:
        a = False
    if a == True:
        username = driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em").text
        os.chdir('D:\python-photo\log')  # 切换到当前目录
        report = open("OP-login.doc", "a")  # 打开报告
        current_time = datetime.datetime.now()
        report.write("\n%s:" % current_time)
        report.write("开始发标，登录成功,账号昵称是：" + username + "\n")
        driver.find_element_by_xpath(".//*[@id='header']/section[2]/nav/ul/li[8]/a").click()
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[2]/a").click()
        #第一个页面
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[1]/aside/label[3]/input").click()
        now = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))  # 标的编号命名格式,也为业务编号
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[2]/aside/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[3]/aside/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[4]/aside/input").send_keys(borrowtitle + now)
        driver.find_element_by_id("username").send_keys(borrowname)
        Select(driver.find_element_by_id("borrow_use")).select_by_visible_text(u"临时周转")
        driver.find_element_by_id("account").send_keys(money)
        driver.find_element_by_xpath(".//*[@id='borrow_style_box']/label/input").click()
        Select(driver.find_element_by_id("borrow_period")).select_by_visible_text(month)
        time.sleep(2)
        driver.find_element_by_id("borrow_apr").clear()
        driver.find_element_by_id("borrow_apr").send_keys(rate)
        Select(driver.find_element_by_id("cashgroup")).select_by_visible_text(cashgroup)
        driver.find_element_by_id("agent_username").send_keys(agentname)
        driver.find_element_by_link_text(u"下一步").click()
        #第二个页面
        Select(driver.find_element_by_id("edu")).select_by_visible_text(u"本科")
        driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[6]/aside/label[1]/input").click()
        driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[7]/aside/input").send_keys(u"四川省南充市")
        driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[8]/aside/input").send_keys(u"四川省成都市青羊区")
        Select(driver.find_element_by_id("category")).select_by_visible_text(u"其他")
        driver.find_element_by_id("account_use").send_keys(u"借钱来耍耍")
        time.sleep(2)
        #上传合同图片，切换iframe#pact_img
        '''
        driver.switch_to.frame("pact_img")
        driver.find_element_by_id("SWFUpload_0").send_keys("D:\\photo\\8.jpg")
        driver.switch_to.default_content()
        time.sleep(2)
        driver.switch_to.frame("user_img_with")
        driver.find_element_by_id("SWFUpload_0").send_keys("D:\\photo\\8.jpg")
        driver.switch_to.default_content()
        '''
        Select(driver.find_element_by_id("province")).select_by_visible_text(u"四川省")
        Select(driver.find_element_by_id("city")).select_by_visible_text(u"成都")
        driver.find_element_by_id("work_info").send_keys(u"工作很好，工资很高")
        driver.find_element_by_xpath(".//*[@id='form1']/ul[3]/li[7]/aside/span[1]/a").click()
        # 进入发标第三个页面
        # 切换iframe
        driver.switch_to.frame("iframebox1")
        Select(driver.find_element_by_xpath(".//*[@id='house_type']")).select_by_visible_text(u"商品房")
        driver.find_element_by_xpath(".//*[@id='house']/li[3]/aside/label[1]/input").click()
        driver.find_element_by_xpath(".//*[@id='house']/li[5]/aside/input").send_keys(u"2015-07-25")
        Select(driver.find_element_by_id("house_live_type")).select_by_visible_text(u"套一")
        Select(driver.find_element_by_id("house_zxqk")).select_by_visible_text(u"精装")
        driver.find_element_by_xpath(".//*[@id='house']/li[8]/aside/input").send_keys(u"100")
        driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").send_keys(u"成都长富新城")
        driver.find_element_by_xpath(".//*[@id='house']/li[10]/aside/input").send_keys(u"房子不错")
        driver.find_element_by_id("house_money").send_keys(u"100")
        driver.find_element_by_id("house_area").send_keys(u"100")
        driver.find_element_by_id("house_address").send_keys(u"成都市天府广场" + now)
        driver.find_element_by_id("house_byuser").send_keys(u"陈强")
        Select(driver.find_element_by_id("house_byuser_type")).select_by_visible_text(u"单独所有")
        driver.find_element_by_xpath(".//*[@id='house']/li[16]/aside/input").send_keys(u"王爆炸")
        Select(driver.find_element_by_id("house_card_type")).select_by_visible_text(u"产权证")
        driver.find_element_by_xpath(".//*[@id='house']/li[18]/aside/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='house']/li[19]/aside/input").send_keys(u"1000")
        driver.find_element_by_xpath(".//*[@id='house']/li[20]/aside/input").send_keys(u"1200")
        driver.find_element_by_xpath(".//*[@id='house']/li[21]/aside/input").send_keys(u"陈强")
        driver.find_element_by_xpath(".//*[@id='house']/li[22]/aside/input").send_keys(u"20000")
        driver.find_element_by_xpath(".//*[@id='house']/li[23]/aside/input[1]").send_keys(u"2017-07-25")
        driver.find_element_by_xpath(".//*[@id='house']/li[23]/aside/input[2]").send_keys(u"2018-07-25")
        driver.find_element_by_xpath(".//*[@id='house']/li[24]/aside/input").send_keys(u"天宸汇力商业保理（深圳）有限公司")
        driver.find_element_by_xpath(".//*[@id='house']/li[25]/aside/input").send_keys(u"2015-09-04")
        driver.switch_to.default_content()
        driver.find_element_by_xpath("//*[@id='form1']/ul[2]/li[6]/aside/input[4]").click()
        # 进入发标第四个页面,并判断是否有奖励标
        driver.find_element_by_xpath(".//*[@id='house']/li[2]/aside/label["+ rewardstate +"]/input").click()
        #rewardstate为1时为无奖励
        if rewardstate == "1":
            driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").click()
            # 切换iframe
            WebElementframe = driver.find_element_by_xpath("html/body/div/iframe")
            driver.switch_to.frame(WebElementframe)
            driver.find_element_by_id("dpTodayInput").click()
            driver.switch_to.default_content()
        # rewardstate为2时为有奖励
        if rewardstate == "2":
            driver.find_element_by_xpath(".//*[@id='status_type']/aside/label["+ rewardmode +"]/input").click()
            #rewardmode为1时为现金奖励
            if rewardmode == "1":
                driver.find_element_by_xpath(".//*[@id='status_1']/aside/input").send_keys(reward)
                driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").click()
                # 切换iframe
                WebElementframe = driver.find_element_by_xpath("html/body/div/iframe")
                driver.switch_to.frame(WebElementframe)
                driver.find_element_by_id("dpTodayInput").click()
                driver.switch_to.default_content()
            # rewardmode为2时为按投资金额比例奖励
            if rewardmode == "2":
                driver.find_element_by_xpath(".//*[@id='status_2']/aside/input").send_keys(reward)
                driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").click()
                # 切换iframe
                WebElementframe = driver.find_element_by_xpath("html/body/div/iframe")
                driver.switch_to.frame(WebElementframe)
                driver.find_element_by_id("dpTodayInput").click()
                driver.switch_to.default_content()
        #driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").send_keys(u"2017-09-05 10:40")
        #截图并保存
        #pic_path = 'D:\\python-photo\\image\\' + now + 'FDL-biao' + '.png'  # 截图保存路径
        #print pic_path
        #driver.save_screenshot(pic_path)  # 截图
        driver.find_element_by_xpath(".//*[@id='house']/li[12]/aside/span[1]/a").click()
        # 判断是否发布标的成功
        #根据业务编号进行搜索标，并进行审核
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[4]/a").click()
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
        #判断是否发布成功
        try:
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]")
            b = True
        except:
            b = False
        if b == True:
            borrowid = driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr/td[1]").text
            print u"借款编号是：" + borrowid
            #进行第一次审核
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/aside/label[1]/input").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/aside/textarea").send_keys(u"审核成功")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/aside/span[1]/a").click()
            #按照业务编号进行搜索标
            driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[4]/a").click()
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
            #进行第二次审核
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='house']/li[12]/aside/span[1]/a").click()
            # 按照业务编号进行搜索标
            driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[4]/a").click()
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
            #进行第三次审核
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/aside/label[1]/input").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/aside/textarea").send_keys(u"审核成功")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/aside/span[1]/a").click()
            #初审完毕，执行发标计划任务，进入投资中的借款
            driver.get("http://task.yidai.co/worthautoissue.task.php")
            time.sleep(2)
            driver.quit()
            return u"借款标题是：" + borrowtitle + now + u",借款人是：" + borrowname  + u"，借款编号是：" + borrowid

def op_fdlnet(adminname, password, borrowtitle, money, rate, cashgroup,borrowname, month, agentname, rewardstate, rewardmode, reward):
    #op_Fdl(运营平台账号, 运营平台密码, 借款金额, 借款年利率, 借款人, P2P登录账号, P2P登录密码, P2P交易密码, 满标复审日期)
    # 定义浏览器及地址
    reload(sys)
    sys.setdefaultencoding('utf-8')
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.implicitly_wait(8)
    driver.get("http://op.yidaip2p.net/")
    # 进行登录co环境的运营平台
    driver.find_element_by_id("adminname").send_keys(adminname)
    driver.find_element_by_id("password").send_keys(password)
    driver.find_element_by_id("authCode").send_keys(u"123456")
    driver.find_element_by_xpath(".//*[@id='submitFrom']/ul/li[4]/input").click()
    # 判断是否登录成功，并输出至日志登录账号名称
    try:
        driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em")
        a = True
    except:
        a = False
    if a == True:
        username = driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em").text
        driver.find_element_by_xpath(".//*[@id='header']/section[2]/nav/ul/li[8]/a").click()
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[2]/a").click()
        #第一个页面
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[1]/aside/label[3]/input").click()
        now = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))  # 标的编号命名格式,也为业务编号
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[2]/aside/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[3]/aside/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[4]/aside/input").send_keys(borrowtitle + now)
        driver.find_element_by_id("username").send_keys(borrowname)
        Select(driver.find_element_by_id("borrow_use")).select_by_visible_text(u"临时周转")
        driver.find_element_by_id("account").send_keys(money)
        driver.find_element_by_xpath(".//*[@id='borrow_style_box']/label/input").click()
        Select(driver.find_element_by_id("borrow_period")).select_by_visible_text(month)
        time.sleep(2)
        driver.find_element_by_id("borrow_apr").clear()
        driver.find_element_by_id("borrow_apr").send_keys(rate)
        Select(driver.find_element_by_id("cashgroup")).select_by_visible_text(cashgroup)
        driver.find_element_by_id("agent_username").send_keys(agentname)
        driver.find_element_by_link_text(u"下一步").click()
        #第二个页面
        Select(driver.find_element_by_id("edu")).select_by_visible_text(u"本科")
        driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[6]/aside/label[1]/input").click()
        driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[7]/aside/input").send_keys(u"四川省南充市")
        driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[8]/aside/input").send_keys(u"四川省成都市青羊区")
        driver.find_element_by_id("account_use").send_keys(u"借钱来耍耍")
        Select(driver.find_element_by_id("province")).select_by_visible_text(u"四川省")
        Select(driver.find_element_by_id("city")).select_by_visible_text(u"成都")
        driver.find_element_by_id("work_info").send_keys(u"工作很好，工资很高")
        driver.find_element_by_xpath(".//*[@id='form1']/ul[3]/li[7]/aside/span[1]/a").click()
        # 进入发标第三个页面
        # 切换iframe
        driver.switch_to.frame("iframebox1")
        Select(driver.find_element_by_xpath(".//*[@id='house_type']")).select_by_visible_text(u"商品房")
        driver.find_element_by_xpath(".//*[@id='house']/li[3]/aside/label[1]/input").click()
        driver.find_element_by_xpath(".//*[@id='house']/li[5]/aside/input").send_keys(u"2015-07-25")
        Select(driver.find_element_by_id("house_live_type")).select_by_visible_text(u"套一")
        Select(driver.find_element_by_id("house_zxqk")).select_by_visible_text(u"精装")
        driver.find_element_by_xpath(".//*[@id='house']/li[8]/aside/input").send_keys(u"100")
        driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").send_keys(u"成都长富新城")
        driver.find_element_by_xpath(".//*[@id='house']/li[10]/aside/input").send_keys(u"房子不错")
        driver.find_element_by_id("house_money").send_keys(u"100")
        driver.find_element_by_id("house_area").send_keys(u"100")
        driver.find_element_by_id("house_address").send_keys(u"成都市天府广场" + now)
        driver.find_element_by_id("house_byuser").send_keys(u"陈强")
        Select(driver.find_element_by_id("house_byuser_type")).select_by_visible_text(u"单独所有")
        driver.find_element_by_xpath(".//*[@id='house']/li[16]/aside/input").send_keys(u"王爆炸")
        Select(driver.find_element_by_id("house_card_type")).select_by_visible_text(u"产权证")
        driver.find_element_by_xpath(".//*[@id='house']/li[18]/aside/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='house']/li[19]/aside/input").send_keys(u"1000")
        driver.find_element_by_xpath(".//*[@id='house']/li[20]/aside/input").send_keys(u"1200")
        driver.find_element_by_xpath(".//*[@id='house']/li[21]/aside/input").send_keys(u"陈强")
        driver.find_element_by_xpath(".//*[@id='house']/li[22]/aside/input").send_keys(u"20000")
        driver.find_element_by_xpath(".//*[@id='house']/li[23]/aside/input[1]").send_keys(u"2017-07-25")
        driver.find_element_by_xpath(".//*[@id='house']/li[23]/aside/input[2]").send_keys(u"2018-07-25")
        driver.find_element_by_xpath(".//*[@id='house']/li[24]/aside/input").send_keys(u"天宸汇力商业保理（深圳）有限公司")
        driver.find_element_by_xpath(".//*[@id='house']/li[25]/aside/input").send_keys(u"2015-09-04")
        driver.switch_to.default_content()
        driver.find_element_by_xpath("//*[@id='form1']/ul[2]/li[6]/aside/input[4]").click()
        # 进入发标第四个页面,并判断是否有奖励标
        driver.find_element_by_xpath(".//*[@id='house']/li[2]/aside/label[" + rewardstate + "]/input").click()
        # rewardstate为1时为无奖励
        if rewardstate == "1":
            driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").click()
            # 切换iframe
            WebElementframe = driver.find_element_by_xpath("html/body/div/iframe")
            driver.switch_to.frame(WebElementframe)
            driver.find_element_by_id("dpTodayInput").click()
            driver.switch_to.default_content()
        # rewardstate为2时为有奖励
        if rewardstate == "2":
            driver.find_element_by_xpath(".//*[@id='status_type']/aside/label[" + rewardmode + "]/input").click()
            # rewardmode为1时为现金奖励
            if rewardmode == "1":
                driver.find_element_by_xpath(".//*[@id='status_1']/aside/input").send_keys(reward)
                driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").click()
                # 切换iframe
                WebElementframe = driver.find_element_by_xpath("html/body/div/iframe")
                driver.switch_to.frame(WebElementframe)
                driver.find_element_by_id("dpTodayInput").click()
                driver.switch_to.default_content()
            # rewardmode为2时为按投资金额比例奖励
            if rewardmode == "2":
                driver.find_element_by_xpath(".//*[@id='status_2']/aside/input").send_keys(reward)
                driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").click()
                # 切换iframe
                WebElementframe = driver.find_element_by_xpath("html/body/div/iframe")
                driver.switch_to.frame(WebElementframe)
                driver.find_element_by_id("dpTodayInput").click()
                driver.switch_to.default_content()
        #driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").send_keys(u"2017-09-05 10:40")
        #截图并保存
        #pic_path = 'D:\\python-photo\\image\\' + now + 'FDL-biao' + '.png'  # 截图保存路径
        #print pic_path
        #driver.save_screenshot(pic_path)  # 截图
        driver.find_element_by_xpath(".//*[@id='house']/li[12]/aside/span[1]/a").click()
        # 判断是否发布标的成功
        #根据业务编号进行搜索标，并进行审核
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[4]/a").click()
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
        #判断是否发布成功
        try:
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]")
            b = True
        except:
            b = False
        if b == True:
            borrowid = driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr/td[1]").text
            print u"借款编号是：" + borrowid
            #进行第一次审核
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/aside/label[1]/input").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/aside/textarea").send_keys(u"审核成功")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/aside/span[1]/a").click()
            #按照业务编号进行搜索标
            driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[4]/a").click()
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
            #进行第二次审核
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='house']/li[12]/aside/span[1]/a").click()
            # 按照业务编号进行搜索标
            driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[4]/a").click()
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
            #进行第三次审核
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/aside/label[1]/input").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/aside/textarea").send_keys(u"审核成功")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/aside/span[1]/a").click()
            #初审完毕，执行发标计划任务，进入投资中的借款
            driver.get("http://task.yidaip2p.net/worthautoissue.task.php")
            driver.quit()
            return u"借款标题是：" + borrowtitle + now + u",借款人是：" + borrowname  + u"，借款编号是：" + borrowid

def op_fangjiadai(adminname, password, borrow_type, borrowtitle, money, rate, username_type, borrowname, month, agentname, cashgroup, huankuanfangshi, biaofengpei, jiekuanpassword):
    #op_Fdl(运营平台账号, 运营平台密码, 借款金额, 借款年利率, 借款人, P2P登录账号, P2P登录密码, P2P交易密码, 满标复审日期)
    # 定义浏览器及地址
    reload(sys)
    sys.setdefaultencoding('utf-8')
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.implicitly_wait(8)
    driver.get("http://op.yidai.co/")
    # 进行登录co环境的运营平台
    driver.find_element_by_id("adminname").send_keys(adminname)
    driver.find_element_by_id("password").send_keys(password)
    driver.find_element_by_id("authCode").send_keys(u"123456")
    driver.find_element_by_xpath(".//*[@id='submitFrom']/ul/li[4]/input").click()
    # 判断是否登录成功，并输出至日志登录账号名称
    try:
        driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em")
        a = True
    except:
        a = False
    if a == True:
        username = driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em").text
        os.chdir('D:\python-photo\log')  # 切换到当前目录
        report = open("OP-login.doc", "a")  # 打开报告
        current_time = datetime.datetime.now()
        report.write("\n%s:" % current_time)
        report.write("开始发标，登录成功,账号昵称是：" + username + "\n")
        driver.find_element_by_xpath(".//*[@id='header']/section[2]/nav/ul/li[8]/a").click()
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[3]/a").click()
        #第一个页面
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[1]/aside/label["+ borrow_type +"]/input").click()
        now = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))  # 标的编号命名格式,也为业务编号
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[2]/aside/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[3]/aside/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[4]/aside/input").send_keys(borrowtitle + now)
        Select(driver.find_element_by_id("username_type")).select_by_visible_text(username_type)
        driver.find_element_by_id("username").send_keys(borrowname)
        driver.find_element_by_xpath(".//*[@id='form1']/ul[1]/li[5]/h6").click()
        if username_type == u"机构":
            driver.find_element_by_id("weituo_ren").send_keys(u"陈强270496")
            driver.find_element_by_id("wtUpload").send_keys("D:\\photo\\1.jpg")
            Select(driver.find_element_by_id("borrow_use")).select_by_visible_text(u"临时周转")
            driver.find_element_by_id("account").send_keys(money)
            driver.find_element_by_xpath(".//*[@id='borrow_style_box']/label[" + huankuanfangshi + "]/input").click()
            Select(driver.find_element_by_id("borrow_period")).select_by_visible_text(month)
            time.sleep(2)
            driver.find_element_by_id("borrow_apr").clear()
            driver.find_element_by_id("borrow_apr").send_keys(rate)
            Select(driver.find_element_by_xpath(".//*[@id='cashgroup']")).select_by_visible_text(cashgroup)
            driver.find_element_by_id("agent_username").send_keys(agentname)
            driver.find_element_by_link_text(u"下一步").click()
            driver.switch_to_alert().accept()
            #driver.find_element_by_xpath(".//*[@id='form1']/ul/li[6]/aside/input").send_keys(u"陈强")
            driver.find_element_by_id("account_use").send_keys(u"借钱来耍耍")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[10]/aside/span[1]/a").click()
        if username_type == u"个人":
            Select(driver.find_element_by_id("borrow_use")).select_by_visible_text(u"临时周转")
            driver.find_element_by_id("account").send_keys(money)
            driver.find_element_by_xpath(".//*[@id='borrow_style_box']/label["+ huankuanfangshi +"]/input").click()
            Select(driver.find_element_by_id("borrow_period")).select_by_visible_text(month)
            time.sleep(2)
            driver.find_element_by_id("borrow_apr").clear()
            driver.find_element_by_id("borrow_apr").send_keys(rate)
            Select(driver.find_element_by_xpath(".//*[@id='cashgroup']")).select_by_visible_text(cashgroup)
            driver.find_element_by_id("agent_username").send_keys(agentname)
            driver.find_element_by_link_text(u"下一步").click()
            driver.switch_to_alert().accept()
            #第二个页面
            Select(driver.find_element_by_id("edu")).select_by_visible_text(u"本科")
            driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[6]/aside/label[1]/input").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[7]/aside/input").send_keys(u"四川省南充市")
            driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li[8]/aside/input").send_keys(u"四川省成都市青羊区")
            Select(driver.find_element_by_id("category")).select_by_visible_text(u"其他")
            driver.find_element_by_id("account_use").send_keys(u"借钱来耍耍")
            Select(driver.find_element_by_id("province")).select_by_visible_text(u"四川省")
            Select(driver.find_element_by_id("city")).select_by_visible_text(u"成都")
            driver.find_element_by_id("work_info").send_keys(u"工作很好，工资很高")
            driver.find_element_by_xpath(".//*[@id='form1']/ul[3]/li[7]/aside/span[1]/a").click()
        # 进入发标第三个页面
        # 切换iframe
        driver.switch_to.frame("iframebox1")
        Select(driver.find_element_by_xpath(".//*[@id='house_type']")).select_by_visible_text(u"商品房")
        driver.find_element_by_xpath(".//*[@id='house']/li[3]/aside/label[1]/input").click()
        driver.find_element_by_xpath(".//*[@id='house']/li[4]/aside/input").send_keys(u"2005-07-25")
        driver.find_element_by_xpath(".//*[@id='house']/li[5]/aside/input").send_keys(u"2015-07-25")
        driver.find_element_by_xpath(".//*[@id='house']/li[6]/aside/input").send_keys(u"100")
        driver.find_element_by_xpath(".//*[@id='house']/li[7]/aside/input").send_keys(u"成都市青羊区宽窄巷子")
        driver.find_element_by_xpath(".//*[@id='house']/li[8]/aside/input").send_keys(u"成都市公证处")
        driver.find_element_by_id("house_money").send_keys(u"100")
        driver.find_element_by_id("house_area").send_keys(u"100")
        driver.find_element_by_id("house_address").send_keys(u"成都市天府广场" + now)
        driver.find_element_by_id("house_byuser").send_keys(u"陈强")
        Select(driver.find_element_by_id("house_byuser_type")).select_by_visible_text(u"单独所有")
        driver.find_element_by_xpath(".//*[@id='house']/li[14]/aside/input").send_keys(now)
        driver.switch_to.default_content()
        driver.find_element_by_xpath(".//*[@id='form1']/ul[2]/li/aside/input[4]").click()
        # 进入发标第四个页面
        #选择标的分配
        driver.find_element_by_xpath(".//*[@id='house']/li[1]/aside/label[" + biaofengpei + "]/input").click()
        driver.find_element_by_xpath(".//*[@id='house']/li[4]/aside/input").click()
        # 切换iframe
        WebElementframe = driver.find_element_by_xpath("html/body/div/iframe")
        driver.switch_to.frame(WebElementframe)
        driver.find_element_by_id("dpTodayInput").click()
        driver.switch_to.default_content()
        #driver.find_element_by_xpath(".//*[@id='house']/li[9]/aside/input").send_keys(u"2017-09-05 10:40")
        #截图并保存
        #pic_path = 'D:\\python-photo\\image\\' + now + 'FDL-biao' + '.png'  # 截图保存路径
        #print pic_path
        #driver.save_screenshot(pic_path)  # 截图
        driver.find_element_by_xpath(".//*[@id='house']/li[7]/aside/span[1]/a").click()
        #生成批次号
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[11]/a").click()
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/a").click()
        driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr/td[1]/input").click()
        driver.find_element_by_xpath("html/body/main/section/div[2]/a").click()
        time.sleep(2)
        driver.find_element_by_xpath(".//*[@id='form_yhk']/ul/li[4]/input[1]").click()
        time.sleep(2)
        driver.find_element_by_xpath(".//*[@id='form_yhk']/ul/li[3]/input[2]").click()
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/a").click()
        driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr/td[1]/input").click()
        driver.find_element_by_xpath("html/body/main/section/div[2]/a[2]").click()
        time.sleep(2)
        driver.find_element_by_xpath(u"(//input[@value='确定'])[2]").click()
        driver.refresh()
        # 判断是否发布标的成功
        #根据业务编号进行搜索标，并进行审核
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[4]/a").click()
        Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
        driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
        #判断是否发布成功
        try:
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]")
            b = True
        except:
            b = False
        if b == True:
            borrowid = driver.find_element_by_xpath(".//*[@id='tabScroll']/div/table/tbody/tr/td[1]").text
            print u"借款编号是：" + borrowid
            #进行第一次审核
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/aside/label[1]/input").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/aside/textarea").send_keys(u"审核成功")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/aside/span[1]/a").click()
            #按照业务编号进行搜索标
            driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[4]/a").click()
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
            #进行第二次审核
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
            driver.find_element_by_id("borrow_password").send_keys(jiekuanpassword)
            driver.find_element_by_xpath(".//*[@id='house']/li[8]/aside/span[1]/a").click()
            # 按照业务编号进行搜索标
            driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[4]/a").click()
            Select(driver.find_element_by_id("searchType")).select_by_visible_text(u"业务编号")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[1]/input").send_keys(now)
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/a").click()
            #进行第三次审核
            driver.find_element_by_xpath(".//*[@id='tabScroll']/table/tbody/tr/td/a[1]").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[2]/aside/label[1]/input").click()
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[3]/aside/textarea").send_keys(u"审核成功")
            driver.find_element_by_xpath(".//*[@id='form1']/ul/li[4]/aside/span[1]/a").click()
            #初审完毕，执行发标计划任务，进入投资中的借款
            driver.get("http://task.yidai.co/worthautoissue.task.php")
            time.sleep(2)
            driver.quit()
            return u"借款标题是：" + borrowtitle + now + u",借款人是：" + borrowname  + u"，借款编号是：" + borrowid
        if b == False:
            return u"发布失败！"
    if a == False:
        return u"登录失败，账号或密码错误！"

def FaHongbao(adminname, op_password, p2p_username, p2p_password, hongbaoid, userid):
    # 定义浏览器及地址
    reload(sys)
    sys.setdefaultencoding('utf-8')
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.implicitly_wait(8)
    driver.get("http://op.yidai.co/")
    # 进行登录co环境的运营平台
    driver.find_element_by_id("adminname").send_keys(adminname)
    driver.find_element_by_id("password").send_keys(op_password)
    driver.find_element_by_id("authCode").send_keys(u"123456")
    driver.find_element_by_xpath(".//*[@id='submitFrom']/ul/li[4]/input").click()
    # 判断是否登录成功，并输出至日志登录账号名称
    try:
        driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em")
        a = True
    except:
        a = False
    if a == True:
        #进入推广管理页面
        driver.find_element_by_xpath(".//*[@id='header']/section[2]/nav/ul/li[5]/a").click()
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[4]/a").click()
        #进入红包页面、手动发放页面
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[2]/a").click()
        #点击新增发放
        driver.find_element_by_xpath("html/body/main/section/div/div[1]/a").click()
        #按照红包序号进行搜索，须记住自己的红包序号
        driver.find_element_by_xpath(".//*[@id='searchFormId']/ul/li[1]/input[1]").send_keys(hongbaoid)
        driver.find_element_by_xpath(".//*[@id='searchFormId']/ul/li[1]/button").click()
        #判断是否有此红包，若有，进入下一步，若无，返回无此红包
        try:
            driver.find_element_by_xpath(".//*[@id='html-2']/tr/td[1]/button")
            b = True
        except:
            b = False
        if b == True:
            #点击添加按钮
            time.sleep(3)
            driver.find_element_by_xpath(".//*[@id='html-2']/tr/td[1]/button").click()
            text = driver.find_element_by_xpath(".//*[@id='tender']/table/tbody/tr/td[4]").text  # 获取此红包的金额大小
            print text
            driver.find_element_by_id("cname").send_keys(u"P2P---陈强")
            #选择少量上传
            driver.find_element_by_id("upload-name").click()
            #输入用户在运营平台的ID号
            driver.find_element_by_id("text-username").send_keys(userid)
            driver.find_element_by_id("FormSubmit").click()
            #进入审核
            driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[4]/a").click()
            driver.find_element_by_xpath("html/body/main/section/div/div[1]/table/tbody/tr[1]/td[6]/a").click()
            driver.find_element_by_xpath(".//*[@id='submitForm']/div[1]/input[1]").click()
            driver.find_element_by_id("audit_remark").send_keys(u"审核成功！")
            driver.find_element_by_id("submitBtn").click()
            #进入P2P前台查看红包是否发放正确
            driver.get("https://www.yidai.co/user/login/")
            time.sleep(2)
            driver.refresh()
            driver.find_element_by_id("keywords").send_keys(p2p_username)
            driver.find_element_by_id("password").send_keys(p2p_password)
            driver.find_element_by_id("login_button").click()
            time.sleep(3)
            driver.refresh()
            #进入红包页面
            driver.find_element_by_xpath("html/body/div[1]/div[2]/div[3]/div[4]/div[2]/div[2]/a[2]/p/span").click()
            #判断是否红包发放成功，成功返回正确，失败返回发放红包失败
            try:
                driver.find_element_by_xpath("html/body/div[1]/div[2]/div[3]/div/div[2]/div[2]/div[2]/div/div[2]/div[1]")
                c = True
            except:
                c = False
            if c == True:
                money = driver.find_element_by_xpath("html/body/div[1]/div[2]/div[3]/div/div[2]/div[2]/div[2]/div/div[2]/div[1]/div[2]").text
                money1 = money.replace(',','')
                print money1
                if money1 == text:
                    driver.quit()
                    return u"红包发放成功，金额为：" + money + "元！"

                else:
                    driver.quit()
                    return u"红包发放失败,金额不正确！"
            if c == False:
                driver.quit()
                return u"红包发放失败！"

        if b == False:
            driver.quit()
            return u"无此红包，请再次确认红包序号！"
    if a == False:
        driver.quit()
        return u"登录失败"


def FaHongbao_net(adminname, op_password, p2p_username, p2p_password, hongbaoid, userid):
    # 定义浏览器及地址
    reload(sys)
    sys.setdefaultencoding('utf-8')
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.implicitly_wait(8)
    driver.get("http://op.yidaip2p.net/")
    # 进行登录co环境的运营平台
    driver.find_element_by_id("adminname").send_keys(adminname)
    driver.find_element_by_id("password").send_keys(op_password)
    driver.find_element_by_id("authCode").send_keys(u"123456")
    driver.find_element_by_xpath(".//*[@id='submitFrom']/ul/li[4]/input").click()
    # 判断是否登录成功，并输出至日志登录账号名称
    try:
        driver.find_element_by_xpath(".//*[@id='header']/section[1]/div/aside/em")
        a = True
    except:
        a = False
    if a == True:
        #进入推广管理页面
        driver.find_element_by_xpath(".//*[@id='header']/section[2]/nav/ul/li[5]/a").click()
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[4]/a").click()
        #进入红包页面、手动发放页面
        driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[2]/a").click()
        #点击新增发放
        driver.find_element_by_xpath("html/body/main/section/div/div[1]/a").click()
        #按照红包序号进行搜索，须记住自己的红包序号
        driver.find_element_by_xpath(".//*[@id='searchFormId']/ul/li[1]/input[1]").send_keys(hongbaoid)
        driver.find_element_by_xpath(".//*[@id='searchFormId']/ul/li[1]/button").click()
        #判断是否有此红包，若有，进入下一步，若无，返回无此红包
        try:
            driver.find_element_by_xpath(".//*[@id='html-2']/tr/td[1]/button")
            b = True
        except:
            b = False
        if b == True:
            #点击添加按钮
            time.sleep(3)
            driver.find_element_by_xpath(".//*[@id='html-2']/tr/td[1]/button").click()
            text = driver.find_element_by_xpath(".//*[@id='tender']/table/tbody/tr/td[4]").text  # 获取此红包的金额大小
            print text
            driver.find_element_by_id("cname").send_keys(u"P2P---陈强")
            #选择少量上传
            driver.find_element_by_id("upload-name").click()
            #输入用户在运营平台的ID号
            driver.find_element_by_id("text-username").send_keys(userid)
            driver.find_element_by_id("FormSubmit").click()
            #进入审核
            driver.find_element_by_xpath(".//*[@id='subnav']/dl/dd[4]/a").click()
            driver.find_element_by_xpath("html/body/main/section/div/div[1]/table/tbody/tr[1]/td[6]/a").click()
            driver.find_element_by_xpath(".//*[@id='submitForm']/div[1]/input[1]").click()
            driver.find_element_by_id("audit_remark").send_keys(u"审核成功！")
            driver.find_element_by_id("submitBtn").click()
            #进入P2P前台查看红包是否发放正确
            driver.get("https://www.yidaip2p.net/user/login/")
            time.sleep(2)
            driver.refresh()
            driver.find_element_by_id("keywords").send_keys(p2p_username)
            driver.find_element_by_id("password").send_keys(p2p_password)
            driver.find_element_by_id("login_button").click()
            time.sleep(3)
            driver.refresh()
            #进入红包页面
            driver.find_element_by_xpath("html/body/div[1]/div[2]/div[3]/div[4]/div[2]/div[2]/a[2]/p/span").click()
            #判断是否红包发放成功，成功返回正确，失败返回发放红包失败
            try:
                driver.find_element_by_xpath("html/body/div[1]/div[2]/div[3]/div/div[2]/div[2]/div[2]/div/div[2]/div[1]")
                c = True
            except:
                c = False
            if c == True:
                money = driver.find_element_by_xpath("html/body/div[1]/div[2]/div[3]/div/div[2]/div[2]/div[2]/div/div[2]/div[1]/div[2]").text
                money1 = money.replace(',','')
                print money1
                if money1 == text:
                    driver.quit()
                    return u"红包发放成功，金额为：" + money + "元！"

                else:
                    driver.quit()
                    return u"红包发放失败,金额不正确！"
            if c == False:
                driver.quit()
                return u"红包发放失败！"

        if b == False:
            driver.quit()
            return u"无此红包，请再次确认红包序号！"
    if a == False:
        driver.quit()
        return u"登录失败"